const { contextBridge, ipcRenderer } = require("electron")

contextBridge.exposeInMainWorld("api", {
  //浏览器发往主进程
  watchDir: (path) => ipcRenderer.send('watch', path),
  onWatchDir: (func) => ipcRenderer.on('watch', (event, ...args) => func(...args)),
  offEvent: (channel, func) => {
    ipcRenderer.off(channel, func)
  },
  //浏览器请求主进程
  selectFile: (type) => ipcRenderer.invoke('addProject', type),
  getProject: (path) => ipcRenderer.invoke('getProject', path),
  getFile: (path) => ipcRenderer.invoke('getFile', path),
  saveFile: (path, content) => ipcRenderer.invoke('saveFile', path, content),
  readDb: (path, exclude) => ipcRenderer.invoke('readDb', path, exclude),
})
